/**
  thread-utils.h - Created by Timothy Morey on 5/27/2012
*/

#ifndef __THREAD_UTILS_H
#define __THREAD_UTILS_H

#ifdef __WINDOWS__
#include <Windows.h>
#else
#include <pthread.h>
#endif

#include "libnvn.h"

/**
  The Thread struct provides a platform independent handle for a thread.
*/
typedef struct
{
#ifdef __WINDOWS__
  HANDLE Handle;     // The windows handle to the thread.
  DWORD Id;          // The id of the thread.
#else
  pthread_t Handle;  // The pthread thread handle.
#endif
} Thread;

/**
  Indicates if the specified thread handle identifies the calling thread.

  @param[in] thread The thread that is being compared to the calling thread.
  @param[out] iscurrent Indicates if the specified thread is the calling thread.

  @return An nvn error code indicating if the operation was successful.
*/
EXPORT int IsCurrentThread(Thread thread, int* iscurrent);

/**
  Causes the thread to sleep a time span given in milliseconds.

  @param mili The number of miliseconds that the thread should sleep.

  @return An nvn error code indicating if the operation was successful.
*/
EXPORT int ThreadSleep(int mili);

/**
  Causes the calling thread to yield the remainder of its CPU time slice to 
  other threads that are waiting to execute.

  @return An nvn error code indicating if the operation was successful.
*/
EXPORT int ThreadYield();

#endif
